//店铺数据模块
import {getShopSellerReq, getGoodsListReq} from '@/api/shop'
const state = {
  shopData: {},
  goodsList: [], //商品列表
}

//getters
const getters = {
  navList(state) {
    return state.goodsList.map(v => v.name)
  },
}

const mutations = {
  SET_SHOPINFO(state, data) {
    state.shopData = data
  },
  SET_GOODS_lIST(state, data) {
    state.goodsList = data
  },
}

const actions = {
  //获取店铺数据
  A_getShopInfo({commit}) {
    return new Promise(async resolve => {
      let res = await getShopSellerReq()
      //解构数据
      let {data} = res.data
      //数据赋值
      commit('SET_SHOPINFO', data)
      resolve()
    })
  },
  //获取商品列表数据
  A_getGoodsData({commit}) {
    return new Promise(async resolve => {
      //发送请求
      let res = await getGoodsListReq()
      //解构参数
      let {code, data} = res.data
      //判断
      if (code === 0) {
        //数据赋值
        commit('SET_GOODS_lIST', data)
        resolve()
      }
    })
  },
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
}
